export default class Song {
	constructor({id,mid,singer,name,album,duration,image,url}){
		this.id = id
		this.mid = mid
		// 歌唱者
		this.singer = singer
		// 歌曲名称
		this.name = name
		// 专辑名称
		this.album = album
		// 播放时间
		this.duration = duration
		// 歌曲图片
		this.image = image
		// 歌曲播放地址
		this.url = url
	}
}
// 构建了一个工厂模式
export function createSong(obj) {
	console.log(obj)
	return new Song({
		id:obj.songid,
		mid:obj.songmid,
		singer:filterSinger(obj.singer),
		name:obj.songname,
		album:obj.albumname,
		duration:obj.interval,
		image:`https://y.gtimg.cn/music/photo_new/T002R300x300M000${obj.albummid}.jpg?max_age=2592000`,
		url:`http://ws.stream.qqmusic.qq.com/${obj.songid}.m4a?fromtag=46`
	})
}

function filterSinger(singer){
	let ret = []
	if(!singer){
		return ''
	}
	singer.forEach((item)=>{
		ret.push(item.name)
	})
	return ret.join('&')
}
